package com.aldobucchi.core.comparison.ordered.impl
{

	import com.aldobucchi.core.comparison.ordered.IOrderedComparator;
	import com.aldobucchi.core.comparison.result.ComparisonResult;
	import com.aldobucchi.core.comparison.result.ComparisonResults;

	
	/**
	 * 
	 * This is a simple implementation of an ordered comparator.
	 * It was developed initially for unit testing.
	 * 
	 * It will internally lowercase every string before using native comparison ( <, >, ==, etc ).
	 * Therefore, it can be used with ANY element type, not just strings.
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class CaseInsensitiveOrderedComparator implements IOrderedComparator
	{
		
		public function compare( value1:*, value2:* ):ComparisonResult
		{
			
			if ( value1 is String )
				value1 = String( value1 ).toLowerCase();
				
			if ( value2 is String )
				value2 = String( value2 ).toLowerCase();
			
			if ( value1 == value2 )
				return ComparisonResults.EQUAL;
			
			if ( value1 > value2 )
				return ComparisonResults.BIGGER;
				
			return ComparisonResults.SMALLER;
		}
		
		
	}
	
}